#include<cstdio>
#include<cstring>
int n;
char a[5001];
short f[2][5001];
int min(int x,int y)
{
	return x<y?x:y;
}
int main()
{
	freopen("test.in","r",stdin);
	scanf("%d",&n);	
	scanf("%c",&a[0]);
	for(int i=1;i<=n;i++)
		scanf("%c",&a[i]);
	memset(f,0,sizeof(f));
	int now =1;
	for(int i=n-1;i>=1;i--)
	{
		now =1-now;
		for(int j=i+1;j<=n;j++)
			if(a[i]==a[j])f[now][j]=f[1-now][j-1];
			else f[now][j]=min(f[1-now][j],f[now][j-1])+1;
	}		
	printf("%d\n",f[now][n]);
	return 0;
}


